#pragma once

#include <iostream>
#include <string>

#include "Protocol.hpp"

using namespace protocol_ns;

// 实现计算功能, 成员函数将来实现回调，参数就穿Request对象， 接收就拿Response对象带出结果

// 将来计算结果根据code判断是否计算正确合法
class CalCulate
{
public:
    CalCulate()
    {
    }
    Response Excute(const Request &req)
    {
        Response res(0, 0);
        switch (req._oper)
        {
        case '+':
        {
            res._result = req._x + req._y;
        }
        break;
        case '-':
        {
            res._result = req._x - req._y;
        }
        break;
        case '*':
        {
            res._result = req._x * req._y;
        }
        break;
        case '/':
        {
            if (req._y == 0)
            {
                res._code = 1; // 除0错误
            }
            else
            {
                res._result = req._x / req._y;
            }
        }
        break;
        case '%':
        {
            if (req._y == 0)
            {
                res._code = 2; // 模0错误
            }
            else
            {
                res._result = req._x % req._y;
            }
        }
        break;
        default:
        {
            res._code = 3; // 非法操作
        }
        break;
        }
        return res;
    }
    ~CalCulate()
    {
    }

private:
};